// deliveryAddress.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        sex: '先生',
        region: ['广东省', '广州市', '海珠区']
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    bindinputName: function(e) {
        var that = this;
        that.setData({
            name: e.detail.value
        })
        console.log(e.detail.value)
    },
    bindchangeSexy: function(e) {
        var that = this;
        that.setData({
            sex: e.detail.value
        })
    },
    bindPhoneNum: function(e) {
        var that = this;
        that.setData({
            mobile: e.detail.value
        })
        var re = /^1[3|4|5|7|8][0-9]\d{4,8}$/;
        if (!re.test(that.data.mobile)) {
            wx.showModal({
                title: "请输入正确的手机号"
            });
            that.setData({
                mobile: ''
            })
            return false;
        }

    },

    bindAddress: function(e) {
        var that = this;
        that.setData({
            address: e.detail.value
        })
    },
    addAddress: function() {
        var that = this;



        var region = that.data.region.join(',');

        if ((!that.data.sex == '') && (!that.data.mobile == '') && (!that.data.address == '') && (!that.data.region == '') && (!that.data.name == '')) {
            wx.request({
                url: app.data.baseUrl + '/AibraUsb/address/add.do',
                data: {
                    openId: app.globalData.openid,
                    sex: that.data.sex,
                    mobile: that.data.mobile,
                    address: that.data.address,
                    name: that.data.name,
                    region: region
                },
                success: function(res) {
                    wx.showToast({
                        title: '保存成功'
                    })

                    wx.navigateBack({
                        detal: 2
                    })
                    console.log("成功")

                }

            })
        } else {
            return false
        }

    },
    bindRegionChange: function(e) {

        var that = this;
        this.setData({
            region: e.detail.value
        })
    }
})